package com.longge;

public class MaxTurbulenceSize {

    public int maxTurbulenceSize(int[] arr) {

        int n = arr.length;

        int ret = 1;
        int left = 0, right = 0;

        while (right < n - 1) {
            if (left==right){
                if (arr[left] == arr[left + 1]) {
                    left++;
                }
                right++;
            }else {
                if (arr[right - 1] < arr[right] && arr[right] > arr[right + 1]) {
                    right++;
                } else if (arr[right - 1] > arr[right] && arr[right] < arr[right + 1]) {
                    right++;
                } else {
                    left = right;
                }
            }
            ret = Math.max(ret, right - left + 1);

        }

        return ret;


    }

    public static void main(String[] args) {


        StringBuilder sb = new StringBuilder();
        for (int i = 0; i <60 ; i++) {
            sb.append("17422994998").append(",");
        }
        System.out.println(sb.toString());
    }
}
